package com.warningrc.system.aspect;

import org.apache.log4j.Logger;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;

/**
 * 日志Aspect
 * 
 * @author 王宁
 * @time Nov 30, 2011
 * @email childe.wangning@gmail.com
 * @weibo http://weibo.com/weibowarning
 */
public class LogAspectJ {

	private Logger log = Logger.getLogger(LogAspectJ.class);

	public void before(JoinPoint jp) {
		String argstr = "";
		for (Object o : jp.getArgs())
			argstr += o + ";";
		log.info("run method[class:" + jp.getTarget().getClass().getName()
				+ ",method:" + jp.getSignature().getName() + ",args:[" + argstr
				+ "]]");
	}

	public void afterReturn(JoinPoint jp, Object returnValue) {
		String argstr = "";
		for (Object o : jp.getArgs())
			argstr += o + ";";
		log.info("afterReturning method[class:"
				+ jp.getTarget().getClass().getName() + ",method:"
				+ jp.getSignature().getName() + ",args:[" + argstr
				+ "],return:" + returnValue + "]");
	}

	public void afterThrowing(JoinPoint jp, RuntimeException e) {
		log.error("Throw Exception:[" + jp.getTarget().getClass().getName()
				+ "." + jp.getSignature().getName() + "]-" + e.getMessage());
	}

	public void around(ProceedingJoinPoint pjp) throws Throwable {
		System.out.println("start around------");
		pjp.proceed(pjp.getArgs());
		System.out.println("stop around------");
	}
}
